<template>
    <div class="temu-lirun-instance-dialog-container">
        <el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="769px">
            <el-form :model="state.temuLirunProductForm" size="default" label-width="80px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="TEMU报价">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.temuQuotePrice" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.priceUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="AM售价">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.amPrice" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.priceUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item :label="state.temuLirunProductInfo.variantCodeOne">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.variantCodeOneValue"
                                        clearable></el-input>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <template v-if="state.btTwoExist">
                        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                            <el-form-item :label="state.temuLirunProductInfo.variantCodeTwo">
                                <el-row>
                                    <el-col :span="16">
                                        <el-input v-model="state.temuLirunProductForm.variantCodeTwoValue"
                                            clearable></el-input>
                                    </el-col>
                                </el-row>
                            </el-form-item>
                        </el-col>
                    </template>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="产品-长">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.productLength" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="产品-宽">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.productWidth" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="产品-高">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.productHeight" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="装箱量">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.outerCartonPackCount"
                                        clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">个</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="装箱-长">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.packetLength" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="装箱-宽">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.packetWidth" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="装箱-高">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.packetHeight" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.productUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="采购成本">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.purchaseCost" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">¥</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="退款占比">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.refundPer" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">%</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="折让占比">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.discountPer" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">%</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="单个产品净重">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.productWeight" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.weightUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="单个产品包装重">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.packageWeight" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.weightUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="Across单件杂费">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.perItemMiscellaneousCost"
                                        clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.priceUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="佐川配置费">
                            <el-row>
                                <el-col :span="16">
                                    <el-input v-model="state.temuLirunProductForm.setupCost" clearable></el-input>
                                </el-col>
                                <el-col :span="8">
                                    <p style="margin: 0; line-height: 32px; text-align: center;">{{
                                        state.temuLirunProductInfo.priceUnit }}</p>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="onCancel" size="default">取 消</el-button>
                    <el-button type="primary" @click="addForm" size="default">
                        {{ state.dialog.submitTxt }}
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts" name="temuLirunProductFormDialog">
import { reactive, ref } from 'vue';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['addInstance']);

// 定义变量内容
const state = reactive({
    temuLirunProductForm: {
        temuQuotePrice: '',                 // TEMU报价
        amPrice: '',                        // am售价
        variantCodeOneValue: '',            // 变体1
        variantCodeTwoValue: '',            // 变体2
        productLength: '',                  // 产品-长
        productWidth: '',                   // 产品-宽
        productHeight: '',                  // 产品-高
        outerCartonPackCount: '',           // 装箱量
        packetLength: '',                   // 装箱-长
        packetWidth: '',                    // 装箱-宽
        packetHeight: '',                   // 装箱-高
        purchaseCost: '',                   // 采购成本-含税（单位是人民币）
        refundPer: '',                      // 退款占比
        discountPer: '',                    // 折让占比
        productWeight: '',                  // 单个产品净重
        packageWeight: '',                  // 单个产品包装重
        perItemMiscellaneousCost: '',       // 单件杂费，默认0.00
        setupCost: '',                      // 配置费，默认0.00
    },
    temuLirunProductInfo: {
        variantCodeOne: '变体1',
        variantCodeTwo: '变体2',
        priceUnit: 'JPY' as any,
        productUnit: 'CM',
        weightUnit: 'KG',
    },
    btTwoExist: false,
    dialog: {
        isShowDialog: false,
        type: '',
        title: '',
        submitTxt: '',
    },
});
// 打开弹窗
const openDialog = (temuLirunProductInfo: TemuLirunProduct) => {
    state.dialog.title = '新增项目单项';
    state.dialog.submitTxt = '确 定';

    state.temuLirunProductInfo = temuLirunProductInfo;

    if ('' != temuLirunProductInfo.variantCodeTwo) {
        state.btTwoExist = true;
    }
    state.temuLirunProductInfo.priceUnit = temuLirunProductInfo.priceUnit;

    state.dialog.type = 'add';
    state.dialog.isShowDialog = true;
    clearTemuLirunProductForm();
};

// 清除弹窗数据
const clearTemuLirunProductForm = () => {
    state.temuLirunProductForm = {
        temuQuotePrice: '',                 // TEMU报价
        amPrice: '',                        // am售价
        variantCodeOneValue: '',            // 变体1
        variantCodeTwoValue: '',            // 变体2
        productLength: '',                  // 产品-长
        productWidth: '',                   // 产品-宽
        productHeight: '',                  // 产品-高
        outerCartonPackCount: '',           // 装箱量
        packetLength: '',                   // 装箱-长
        packetWidth: '',                    // 装箱-宽
        packetHeight: '',                   // 装箱-高
        purchaseCost: '',                   // 采购成本-含税（单位是人民币）
        refundPer: '',                      // 退款占比
        discountPer: '',                    // 折让占比
        productWeight: '',                  // 单个产品净重
        packageWeight: '',                  // 单个产品包装重
        perItemMiscellaneousCost: '',       // 单件杂费，默认0.00
        setupCost: '',                      // 配置费，默认0.00
    }
}

// 关闭弹窗
const closeDialog = () => {
    state.dialog.isShowDialog = false;
};

// 取消
const onCancel = () => {
    closeDialog();
};

// 提交
async function addForm() {
    closeDialog(); // 关闭弹窗
    const form = state.temuLirunProductForm;
    emit('addInstance', form);
};
// 暴露变量
defineExpose({
    openDialog,
});
</script>
